package com.neusoft.elmboot.controller;

import com.neusoft.elmboot.common.utils.VerifyCodeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

@RestController
@Slf4j

public class VerifyCodeController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private VerifyCodeUtil verifyCodeUtil;

    @GetMapping("/geneCode")
    public void generateCode(HttpServletResponse response) throws IOException {
        //生成随机码图片
        VerifyCodeUtil.output(verifyCodeUtil.getImage(),response.getOutputStream());
        System.out.println("-----随机数文本内容-----"+verifyCodeUtil.getText());
        //存到redis中

        redisTemplate.opsForValue().set("elm:user:login:verityCode",verifyCodeUtil.getText(),5*60, TimeUnit.SECONDS);


    }

}
